<?php
declare (strict_types = 1);

namespace app\admin\controller;
use think\facade\View;
use think\facade\Db;
class Category extends AdminBase
{
    public function index()
    {
        return View::fetch();
    }
    public function add()
    {
        return View::fetch();
    }

    public function save()
    {
        $pid = input('param.pid',0,'intval');
        $name = input('param.name','','trim');

        //参数校验
        $data=[
            'pid'=>$pid,
            'name'=>$name,
        ];
       
        $validate = new \app\admin\validate\Category();
        if(!$validate->check($data)){
            return show(config('status.error'),$validate->getError());
        }
        // try {
        //     $result = (new CategoryBus()->add($data));
        // } catch (\Exception $e) {
        //     return show(config('status.error'),$e->getMessage());
        // } 
        $res = Db::name('category')->insert($data);
                     
        return show(config('status.success'),'数据新增成功');
    }

   
}
